package com.iwhalecloud.bss.kite.cucc.common.constant;

public class RandomUtil {

    private Data intarray[];

    private Data chararray[];

    private Data intarray_dc[];

    // 保存产生的数字密码
    private StringBuffer s1;

    private StringBuffer s2;

    // 保存产生的数字和字母组合密码
    private StringBuffer s3;

    public RandomUtil() {
        intarray = new Data[10];
        intarray_dc = new Data[10];
        chararray = new Data[52];
        s1 = new StringBuffer();
        s2 = new StringBuffer();
        s2.append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        s3 = new StringBuffer();
        for (int i = 0; i < 52; i++) {
            Data temp1 = new Data(s2.charAt(i), 0);
            chararray[i] = temp1;
        }
        for (int i = 0; i < 10; i++) {
            Data temp = new Data(i, 0);
            intarray[i] = temp;
            Data temp1 = new Data(i, 0);
            intarray_dc[i] = temp1;
        }

    }

    /**
     * 产生数字组成的密码
     *
     * @param length 欲产生的密码长度
     * @return 密码字符串(数字)
     */
    public String generatePassworrd(int length) {
        while (s1.length() < length) {
            int t = (int) Math.floor(10 * Math.random());
            int k = s1.length() / 10;
            if (intarray[t].getCount() == k) {
                s1.append(intarray[t].getNum());
                intarray[t].setCou(k + 1);
            }
        }
        return s1.toString();
    }

}

class Data {
    public int num;

    private int count;

    private char su;

    public Data(int i, int flag) {
        num = i;
        count = flag;
    }

    public Data(char c, int flag) {
        su = c;
        count = flag;
    }

    public void setCou(int flag) {
        count = flag;
    }

    public int getNum() {
        return num;
    }

    public char getChar() {
        return su;
    }

    public int getCount() {
        return count;
    }
};
